package com.ruoyi.project.system.smsnotice.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.system.smsnotice.domain.SmsNotice;
import com.ruoyi.project.system.smsnotice.service.ISmsNoticeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 短信通知Controller
 * 
 * @author LCL
 * @date 2020-12-22
 */
@Controller
@RequestMapping("/system/smsnotice")
public class SmsNoticeController extends BaseController
{
    private String prefix = "system/smsnotice";

    @Autowired
    private ISmsNoticeService smsNoticeService;

    @RequiresPermissions("system:smsnotice:view")
    @GetMapping()
    public String smsnotice()
    {
        return prefix + "/smsnotice";
    }

    /**
     * 查询短信通知列表
     */
    @RequiresPermissions("system:smsnotice:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(SmsNotice smsNotice)
    {
        startPage();
        List<SmsNotice> list = smsNoticeService.selectSmsNoticeList(smsNotice);
        return getDataTable(list);
    }

    /**
     * 导出短信通知列表
     */
    @RequiresPermissions("system:smsnotice:export")
    @Log(title = "短信通知", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(SmsNotice smsNotice)
    {
        List<SmsNotice> list = smsNoticeService.selectSmsNoticeList(smsNotice);
        ExcelUtil<SmsNotice> util = new ExcelUtil<SmsNotice>(SmsNotice.class);
        return util.exportExcel(list, "smsnotice");
    }

    /**
     * 新增短信通知
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存短信通知
     */
    @RequiresPermissions("system:smsnotice:add")
    @Log(title = "短信通知", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(SmsNotice smsNotice)
    {
        return toAjax(smsNoticeService.insertSmsNotice(smsNotice));
    }

    /**
     * 修改短信通知
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        SmsNotice smsNotice = smsNoticeService.selectSmsNoticeById(id);
        mmap.put("smsNotice", smsNotice);
        return prefix + "/edit";
    }

    /**
     * 修改保存短信通知
     */
    @RequiresPermissions("system:smsnotice:edit")
    @Log(title = "短信通知", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(SmsNotice smsNotice)
    {
        return toAjax(smsNoticeService.updateSmsNotice(smsNotice));
    }

    /**
     * 删除短信通知
     */
    @RequiresPermissions("system:smsnotice:remove")
    @Log(title = "短信通知", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(smsNoticeService.deleteSmsNoticeByIds(ids));
    }
}
